/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package adcomputer;


import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;


public class BaseDeDatos {
    
    
   String  nombrebd, usuario, password;
   Connection conexion;
   
   
   public BaseDeDatos()
   {
       nombrebd="localhost/DatosTienda";
       usuario="root";
       password="1234";
        try {
            DriverManager.registerDriver(new org.gjt.mm.mysql.Driver());
        } catch (SQLException ex) {
            Logger.getLogger(BaseDeDatos.class.getName()).log(Level.SEVERE, null, ex);
        }
   }
   public void conectar()
   {
        try {
            conexion=DriverManager.getConnection("jdbc:mysql://localhost:3307/datostienda","usuario","1234");
        } catch (SQLException ex) {
            Logger.getLogger(BaseDeDatos.class.getName()).log(Level.SEVERE, null, ex);
        }
   }
   
   public void desconectar()       
   {
        try {
            conexion.close();
        } catch (SQLException ex) {
            Logger.getLogger(BaseDeDatos.class.getName()).log(Level.SEVERE, null, ex);
        }
   }
   
   public ResultSet consultar(String cad)
   {
        try {
            Statement st=conexion.createStatement();
            ResultSet rs=st.executeQuery(cad);
            return rs;
        } catch (SQLException ex) {
            Logger.getLogger(BaseDeDatos.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
   
   }
   
   public int modificar(String cad)
   {
   
       try {
            Statement st=conexion.createStatement();
            int rs =st.executeUpdate(cad);
            return rs;
        } catch (SQLException ex) {
            Logger.getLogger(BaseDeDatos.class.getName()).log(Level.SEVERE, null, ex);
        }
        return 0;
       
   }
    
}
